/********************************************************************************
 * FavouriteAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Jan 5, 2009 10:59:01 AM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/
package com.printeverywhere.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.printeverywhere.delegator.CategoryManagerServiceDelegator;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.delegator.LocationCategoriesServiceDelegator;
import com.printeverywhere.delegator.UserServiceDelegator;
import com.printeverywhere.dto.MyAccountCount;
import com.printeverywhere.dto.User;
import com.printeverywhere.dto.UserFavoritesCategory;
import com.printeverywhere.dto.UserFavoritesCompanyprofile;
import com.printeverywhere.dto.UserFavoritesSearch;
import com.printeverywhere.dto.UserFavoritesShops;
import com.printeverywhere.dto.UserFavoritesUsers;
import com.printeverywhere.util.AdminConstants;
import com.printeverywhere.util.AttributeConstants;
import com.printeverywhere.util.DateUtil;
import com.printeverywhere.util.SearchCriteria;
import com.printeverywhere.util.SessionUtil;

public class FavouriteAction extends FrontBaseSupport implements ServletRequestAware {

	private static final long serialVersionUID = 1L;

	private HttpServletRequest request;

	private String textContent;

	private String location;

	private String action;

	private int count;

	private String title;

	private int id;

	private SearchCriteria searchCriteria = new SearchCriteria();

	private User user;

	UserFavoritesUsers userFavoritesUsers;

	UserFavoritesSearch userFavoritesSearch;

	UserFavoritesShops userFavoritesShops;

	UserFavoritesCompanyprofile userFavoritesProfile;

	UserFavoritesCategory userFavoritesCategory;

	private String part;

	private String note;

	private MyAccountCount myAccountCount;

	private List<UserFavoritesCategory> favoritesCategoriesList = new ArrayList<UserFavoritesCategory>();

	private List<UserFavoritesUsers> favoritesUsersList = new ArrayList<UserFavoritesUsers>();

	private List<UserFavoritesShops> favoritesShopsList = new ArrayList<UserFavoritesShops>();

	private List<UserFavoritesCompanyprofile> favoritesProfileList = new ArrayList<UserFavoritesCompanyprofile>();

	private List<UserFavoritesSearch> favoritesSearchList = new ArrayList<UserFavoritesSearch>();

	public FavouriteAction() {
		super(true, false);
		setMyAccount(true);
	}

	public String execute(){
		return SUCCESS;
	}

	public String favoriteCategories() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			this.favoritesCategoriesList = (List<UserFavoritesCategory>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, UserFavoritesCategory.class);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String favoriteUsers(){
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			this.favoritesUsersList = (List<UserFavoritesUsers>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, UserFavoritesUsers.class);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String favoriteProfile() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			this.favoritesProfileList = (List<UserFavoritesCompanyprofile>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, UserFavoritesCompanyprofile.class);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String favoriteSearches() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			this.favoritesSearchList = (List<UserFavoritesSearch>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, UserFavoritesSearch.class);
		}catch (Exception e) {
			return INPUT;
		}
			return SUCCESS;
	}

	public String favoriteShops() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			this.favoritesShopsList = (List<UserFavoritesShops>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, UserFavoritesShops.class);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addToFavoriteUsers() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			count = CommonFunctionDelegator.getCountByCriterion(criterionList, UserFavoritesUsers.class);
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setFavoriteUsers(count);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addToFavoriteShops() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			count = CommonFunctionDelegator.getCountByCriterion(criterionList, UserFavoritesShops.class);
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setFavoriteShops(count);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addToFavoriteProfile() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			count = CommonFunctionDelegator.getCountByCriterion(criterionList, UserFavoritesCompanyprofile.class);
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setFavoriteCompany(count);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addToFavoriteCategory() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			count = CommonFunctionDelegator.getCountByCriterion(criterionList, UserFavoritesCategory.class);
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setFavoriteCategories(count);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addToFavoriteSearch() {
		try{
			List<Criterion> criterionList = new ArrayList<Criterion>();
			criterionList.add(Restrictions.eq("user", SessionUtil.getUser(request)));
			count = CommonFunctionDelegator.getCountByCriterion(criterionList, UserFavoritesSearch.class);
			myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
			myAccountCount.setFavoriteSearches(count);
			request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteFavoriteUsers() {
		try{
			searchCriteria.removeAllAttribute();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesUsersList = (List<UserFavoritesUsers>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesUsers.class);

			if(this.favoritesUsersList != null && this.favoritesUsersList.size() > 0) {
				this.userFavoritesUsers = (this.favoritesUsersList.get(0));
				CommonFunctionDelegator.GeneralDelete(this.userFavoritesUsers);
				myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
				if(myAccountCount.getFavoriteUsers() > 0){
					myAccountCount.setFavoriteUsers(myAccountCount.getFavoriteUsers() - 1);
				}
				request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteMultiFavoriteUser() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));

			if (request.getParameter("selectedCategory") != null) {
				String[] categories = request.getParameterValues("selectedCategory");
				for (String category : categories) {
					searchCriteria.setAttribute("id", Integer.parseInt(category));
					this.favoritesUsersList = (List<UserFavoritesUsers>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesUsers.class);

					if(this.favoritesUsersList != null && this.favoritesUsersList.size() > 0) {
						this.userFavoritesUsers = (this.favoritesUsersList.get(0));
						CommonFunctionDelegator.GeneralDelete(this.userFavoritesUsers);
						myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
						if(myAccountCount.getFavoriteUsers() > 0){
							myAccountCount.setFavoriteUsers(myAccountCount.getFavoriteUsers() - 1);
						}
						request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
					}
				}
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}
	public String deleteMultiFavoriteShop() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));

			if (request.getParameter("selectedCategory") != null) {
				String[] categories = request.getParameterValues("selectedCategory");
				for (String category : categories) {
					searchCriteria.setAttribute("id", Integer.parseInt(category));
					this.favoritesShopsList = (List<UserFavoritesShops>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesShops.class);

					if(this.favoritesShopsList != null && this.favoritesShopsList.size() > 0) {
						this.userFavoritesShops = (this.favoritesShopsList.get(0));
						CommonFunctionDelegator.GeneralDelete(this.userFavoritesShops);
						myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
						if(myAccountCount.getFavoriteShops() > 0){
							myAccountCount.setFavoriteShops(myAccountCount.getFavoriteShops() - 1);
						}
						request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
					}
				}
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteMultiFavoriteProfiles() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));

			if (request.getParameter("selectedCategory") != null) {
				String[] categories = request.getParameterValues("selectedCategory");
				for (String category : categories) {
					searchCriteria.setAttribute("id", Integer.parseInt(category));
					this.favoritesProfileList = (List<UserFavoritesCompanyprofile>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCompanyprofile.class);

					if(this.favoritesProfileList != null && this.favoritesProfileList.size() > 0) {
						this.userFavoritesProfile = (this.favoritesProfileList.get(0));
						CommonFunctionDelegator.GeneralDelete(this.userFavoritesProfile);
						myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
						if(myAccountCount.getFavoriteCompany() > 0){
							myAccountCount.setFavoriteCompany(myAccountCount.getFavoriteCompany() - 1);
						}
						request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
					}
				}
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}
	public String editFavoriteShops() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesShopsList = (List<UserFavoritesShops>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesShops.class);

			if(this.favoritesShopsList != null && this.favoritesShopsList.size() > 0) {
				this.userFavoritesShops = (this.favoritesShopsList.get(0));
			}

			addToFavoriteShops();
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteFavoriteShops() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesShopsList = (List<UserFavoritesShops>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesShops.class);

			if(this.favoritesShopsList != null && this.favoritesShopsList.size() > 0) {
				this.userFavoritesShops = (this.favoritesShopsList.get(0));
				CommonFunctionDelegator.GeneralDelete(this.userFavoritesShops);
				myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
				if(myAccountCount.getFavoriteShops() > 0){
					myAccountCount.setFavoriteShops(myAccountCount.getFavoriteShops() - 1);
				}
				request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String editFavoriteProfile() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesProfileList = (List<UserFavoritesCompanyprofile>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCompanyprofile.class);

			if(this.favoritesProfileList != null && this.favoritesProfileList.size() > 0) {
				this.userFavoritesProfile = (this.favoritesProfileList.get(0));
			}

			addToFavoriteProfile();
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteFavoriteProfile() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesProfileList = (List<UserFavoritesCompanyprofile>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCompanyprofile.class);

			if(this.favoritesProfileList != null && this.favoritesProfileList.size() > 0) {
				this.userFavoritesProfile = (this.favoritesProfileList.get(0));
				CommonFunctionDelegator.GeneralDelete(this.userFavoritesProfile);
				myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
				if(myAccountCount.getFavoriteCompany() > 0){
					myAccountCount.setFavoriteCompany(myAccountCount.getFavoriteCompany() - 1);
				}
				request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String editFavoriteCategory() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesCategoriesList = (List<UserFavoritesCategory>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCategory.class);

			if(this.favoritesCategoriesList != null && this.favoritesCategoriesList.size() > 0) {
				this.userFavoritesCategory = (this.favoritesCategoriesList.get(0));
			}

			addToFavoriteCategory();
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteFavoriteCategory() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesCategoriesList = (List<UserFavoritesCategory>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCategory.class);

			if(this.favoritesCategoriesList != null && this.favoritesCategoriesList.size() > 0) {
				this.userFavoritesCategory = (this.favoritesCategoriesList.get(0));
				CommonFunctionDelegator.GeneralDelete(this.userFavoritesCategory);
				myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
				if(myAccountCount.getFavoriteCategories() > 0){
					myAccountCount.setFavoriteCategories(myAccountCount.getFavoriteCategories() - 1);
				}
				request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteMultiFavoriteCategory() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));

			if (request.getParameter("selectedCategory") != null) {
				String[] categories = request.getParameterValues("selectedCategory");
				for (String category : categories) {
					searchCriteria.setAttribute("id", Integer.parseInt(category));
					this.favoritesCategoriesList = (List<UserFavoritesCategory>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCategory.class);


					if(this.favoritesCategoriesList != null && this.favoritesCategoriesList.size() > 0) {
						this.userFavoritesCategory = (this.favoritesCategoriesList.get(0));
						CommonFunctionDelegator.GeneralDelete(this.userFavoritesCategory);
						myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
						if(myAccountCount.getFavoriteCategories() > 0){
							myAccountCount.setFavoriteCategories(myAccountCount.getFavoriteCategories() - 1);
						}
						request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
					}
				}
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteMultiFavoriteSearches() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));

			if (request.getParameter("selectedCategory") != null) {
				String[] categories = request.getParameterValues("selectedCategory");
				for (String category : categories) {
					searchCriteria.setAttribute("id", Integer.parseInt(category));
					this.favoritesSearchList = (List<UserFavoritesSearch>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesSearch.class);


					if(this.favoritesSearchList != null && this.favoritesSearchList.size() > 0) {
						this.userFavoritesSearch = (this.favoritesSearchList.get(0));
						CommonFunctionDelegator.GeneralDelete(this.userFavoritesSearch);
						myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
						if(myAccountCount.getFavoriteSearches() > 0){
							myAccountCount.setFavoriteSearches(myAccountCount.getFavoriteSearches() - 1);
						}
						request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
					}
				}
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}


	public String editFavoriteSearch() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesSearchList = (List<UserFavoritesSearch>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesSearch.class);

			if(this.favoritesSearchList != null && this.favoritesSearchList.size() > 0) {
				this.userFavoritesSearch = (this.favoritesSearchList.get(0));
			}

			addToFavoriteCategory();
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String deleteFavoriteSearch() {
		try{
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("user", SessionUtil.getUser(request));
			searchCriteria.setAttribute("id", Integer.parseInt(request.getParameter("uid")));

			this.favoritesSearchList = (List<UserFavoritesSearch>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesSearch.class);

			if(this.favoritesSearchList != null && this.favoritesSearchList.size() > 0) {
				this.userFavoritesSearch = (this.favoritesSearchList.get(0));
				CommonFunctionDelegator.GeneralDelete(this.userFavoritesSearch);
				myAccountCount = (MyAccountCount) request.getSession().getAttribute(AttributeConstants.MYACCOUNTCOUNT);
				if(myAccountCount.getFavoriteSearches() > 0){
					myAccountCount.setFavoriteSearches(myAccountCount.getFavoriteSearches() - 1);
				}
				request.getSession().setAttribute(AttributeConstants.MYACCOUNTCOUNT, myAccountCount);
			}
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addUserToFavoriteUsers() {
		try{
			this.user = UserServiceDelegator.getUserByUserId(this.textContent);
			User mainUser = SessionUtil.getUser(request);
			searchCriteria.removeAllAttribute();
			searchCriteria.setAttribute(AdminConstants.USER, mainUser);
			searchCriteria.setAttribute("userIdFav", user);
			List<UserFavoritesUsers> userFavoritesUsersList = (List<UserFavoritesUsers>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesUsers.class);
			if(userFavoritesUsersList.size() > 0){
				addActionError("User already added as favourite user.");
				addToFavoriteUsers();
				return INPUT;
			}else if(user != null && user.getId() != mainUser.getId() && !user.getId().equals(mainUser.getId())) {
				this.userFavoritesUsers = new UserFavoritesUsers();
				userFavoritesUsers.setDate(DateUtil.getTodaysDate());
				userFavoritesUsers.setUser(mainUser);
				userFavoritesUsers.setUserIdFav(user);
				CommonFunctionDelegator.generalInsertbyobj(userFavoritesUsers);
				addToFavoriteUsers();
				this.title = "Users";
				this.part = "User";
				this.action = "addNoteToFavoriteUsers.htm";

			return SUCCESS;
		} else {
			addActionMessage("You can't add yourself or non-exising user...");
			addToFavoriteUsers();
			return INPUT;
		}}catch (Exception e) {
			return INPUT;
		}
	}

	public String addShopToFavoriteShops() {
		try{
			User mainUser = SessionUtil.getUser(request);

			userFavoritesShops.setDate(DateUtil.getTodaysDate());
			userFavoritesShops.setUser(mainUser);
			userFavoritesShops.setCategory(CategoryManagerServiceDelegator.get(6));
			userFavoritesShops.setRegion(LocationCategoriesServiceDelegator.get(1));
			userFavoritesShops.setLocation(this.location);
			userFavoritesShops.setName(this.textContent);

			if(userFavoritesShops.getId() != null && userFavoritesShops.getId() != 0) {
				UserFavoritesShops tmpUserFavoritesShops = (UserFavoritesShops) CommonFunctionDelegator.getObjectById("id", userFavoritesShops.getId(), UserFavoritesShops.class);
				userFavoritesShops.setNote(tmpUserFavoritesShops.getNote());
				CommonFunctionDelegator.generalUpdatebyobj(userFavoritesShops);
			}
			else
				CommonFunctionDelegator.generalInsertbyobj(userFavoritesShops);
			addToFavoriteShops();
			this.title = "Shops";
			this.part = "Shop";
			this.action = "addNoteToFavoriteShops.htm";
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addShopToFavoriteProfile() {
		try{
			User mainUser = SessionUtil.getUser(request);

			userFavoritesProfile.setDate(DateUtil.getTodaysDate());
			userFavoritesProfile.setUser(mainUser);
			userFavoritesProfile.setGeneralCategories(CategoryManagerServiceDelegator.get(6));
			userFavoritesProfile.setRegion(LocationCategoriesServiceDelegator.get(1));
			userFavoritesProfile.setLocation(this.location);
			userFavoritesProfile.setName(this.textContent);

			if(userFavoritesProfile.getId() != null && userFavoritesProfile.getId() != 0) {
				UserFavoritesCompanyprofile tmpUserFavoritesProfile = (UserFavoritesCompanyprofile) CommonFunctionDelegator.getObjectById("id", userFavoritesProfile.getId(), UserFavoritesCompanyprofile.class);
				userFavoritesProfile.setNote(tmpUserFavoritesProfile.getNote());
				CommonFunctionDelegator.generalUpdatebyobj(userFavoritesProfile);
			}
			else
				CommonFunctionDelegator.generalInsertbyobj(userFavoritesProfile);
			addToFavoriteProfile();
			this.title = "Profiles";
			this.part = "Profile";
			this.action = "addNoteToFavoriteProfile.htm";

		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addCategoryToFavoriteCategory() {
		try{
			User mainUser = SessionUtil.getUser(request);
			searchCriteria.removeAllAttribute();
			searchCriteria.setAttribute(AdminConstants.USER, mainUser);
			searchCriteria.setAttribute("generalCategories.categoryId", Integer.parseInt(request.getParameter("categoryId")));
			List<UserFavoritesCategory> userFavoritesCategoryList = (List<UserFavoritesCategory>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, UserFavoritesCategory.class);
			if(userFavoritesCategoryList.size() > 0){
				addActionError("Category already exist.");
				return INPUT;
			}
			userFavoritesCategory.setDateAdded(DateUtil.getTodaysDate());
			userFavoritesCategory.setUser(mainUser);
			userFavoritesCategory.setGeneralCategories(CategoryManagerServiceDelegator.get(Integer.parseInt(request.getParameter("categoryId"))));

			if(userFavoritesCategory.getId() != null && userFavoritesCategory.getId() != 0) {
				UserFavoritesCategory tmpUserCategory = (UserFavoritesCategory) CommonFunctionDelegator.getObjectById("id", userFavoritesCategory.getId(), UserFavoritesCategory.class);
				userFavoritesCategory.setNote(tmpUserCategory.getNote());
				CommonFunctionDelegator.generalUpdatebyobj(userFavoritesCategory);
			}
			else
				CommonFunctionDelegator.generalInsertbyobj(userFavoritesCategory);
			addToFavoriteCategory();
			this.title = "Categories";
			this.part = "Category";
			this.action = "addNoteToFavoriteCategory.htm";
		}catch (Exception e) {
			addActionError("Please, select the category...");
			return INPUT;
		}
		return SUCCESS;
	}

	public String addSearchToFavoriteSearch() {
		if(this.textContent != null && this.textContent.trim().length() > 0) {
			try{
				User mainUser = SessionUtil.getUser(request);

				userFavoritesSearch.setDate(DateUtil.getTodaysDate());
				userFavoritesSearch.setUser(mainUser);
				userFavoritesSearch.setCategoryId(CategoryManagerServiceDelegator.getWOS(6));
				userFavoritesSearch.setRegionId(LocationCategoriesServiceDelegator.getWOS(1));
				userFavoritesSearch.setLocation(this.location);
				userFavoritesSearch.setName(this.textContent);

				if(userFavoritesSearch.getId() != null && userFavoritesSearch.getId() != 0) {
					UserFavoritesSearch tmpUserSearch = (UserFavoritesSearch) CommonFunctionDelegator.getObjectById("id", userFavoritesCategory.getId(), UserFavoritesSearch.class);
					userFavoritesSearch.setNote(tmpUserSearch.getNote());
					CommonFunctionDelegator.generalUpdatebyobj(userFavoritesSearch);
				}
				else
					CommonFunctionDelegator.generalInsertbyobj(userFavoritesSearch);

				this.title = "Searches";
				this.part = "Search";
				this.action = "addNoteToFavoriteSearch.htm";
			}catch (Exception e) {
				addActionError("Please, enter valid information...");
				return INPUT;
			}
		} else {
			addActionError("Please insert search words...");
			return INPUT;
		}
		return SUCCESS;
	}

	public String addEditNoteToFavoriteUsers() {
		try{
			if(request.getParameter("fuid") != null) {
				this.userFavoritesUsers = (UserFavoritesUsers) CommonFunctionDelegator.getObjectById("id", Integer.parseInt(request.getParameter("fuid")), UserFavoritesUsers.class);
			}

			this.title = "Users";
			this.part = "User";
			this.action = "addNoteToFavoriteUsers.htm";
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addEditNoteToFavoriteShops() {
		try{
			if(request.getParameter("fuid") != null) {
				this.userFavoritesShops = (UserFavoritesShops) CommonFunctionDelegator.getObjectById("id", Integer.parseInt(request.getParameter("fuid")), UserFavoritesShops.class);
			}

			this.title = "Shops";
			this.part = "Shop";
			this.action = "addNoteToFavoriteShops.htm";
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addEditNoteToFavoriteCategory() {
		try{
			if(request.getParameter("fuid") != null) {
				this.userFavoritesCategory = (UserFavoritesCategory) CommonFunctionDelegator.getObjectById("id", Integer.parseInt(request.getParameter("fuid")), UserFavoritesCategory.class);
			}

			this.title = "Categories";
			this.part = "Category";
			this.action = "addNoteToFavoriteCategory.htm";
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addEditNoteToFavoriteSearch() {
		try{
			if(request.getParameter("fuid") != null) {
				this.userFavoritesSearch = (UserFavoritesSearch) CommonFunctionDelegator.getObjectById("id", Integer.parseInt(request.getParameter("fuid")), UserFavoritesSearch.class);
			}

			this.title = "Searches";
			this.part = "Search";
			this.action = "addNoteToFavoriteSearch.htm";
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addNoteToFavoriteUsers() {
		try{
			this.userFavoritesUsers = (UserFavoritesUsers) CommonFunctionDelegator.getObjectById("id", this.id, UserFavoritesUsers.class);
			this.userFavoritesUsers.setNote(this.note);
			CommonFunctionDelegator.generalUpdatebyobj(this.userFavoritesUsers);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addNoteToFavoriteShops() {
		try{
			this.userFavoritesShops = (UserFavoritesShops) CommonFunctionDelegator.getObjectById("id", this.id, UserFavoritesShops.class);
			this.userFavoritesShops.setNote(this.note);
			CommonFunctionDelegator.generalUpdatebyobj(this.userFavoritesShops);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addNoteToFavoriteProfile() {
		try{
			this.userFavoritesProfile = (UserFavoritesCompanyprofile) CommonFunctionDelegator.getObjectById("id", this.id, UserFavoritesCompanyprofile.class);
			this.userFavoritesProfile.setNote(this.note);
			CommonFunctionDelegator.generalUpdatebyobj(this.userFavoritesProfile);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addNoteToFavoriteCategory() {
		try{
			this.userFavoritesCategory = (UserFavoritesCategory) CommonFunctionDelegator.getObjectById("id", this.id, UserFavoritesCategory.class);
			this.userFavoritesCategory.setNote(this.note);
			CommonFunctionDelegator.generalUpdatebyobj(this.userFavoritesCategory);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}

	public String addNoteToFavoriteSearch() {
		try{
			this.userFavoritesSearch = (UserFavoritesSearch) CommonFunctionDelegator.getObjectById("id", this.id, UserFavoritesSearch.class);
			this.userFavoritesSearch.setNote(this.note);
			CommonFunctionDelegator.generalUpdatebyobj(this.userFavoritesSearch);
		}catch (Exception e) {
			return INPUT;
		}
		return SUCCESS;
	}


	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public List<UserFavoritesUsers> getFavoritesUsersList() {
		return favoritesUsersList;
	}

	public int getCount() {
		return count;
	}

	@RequiredStringValidator(message="Please enter value for Words to search for")
	public String getTextContent() {
		return textContent;
	}

	public void setTextContent(String textContent) {
		this.textContent = textContent;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getTitle() {
		return title;
	}

	public String getPart() {
		return part;
	}

	public User getUser() {
		return user;
	}

	public UserFavoritesUsers getUserFavoritesUsers() {
		return userFavoritesUsers;
	}

	public String getAction() {
		return action;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List<UserFavoritesShops> getFavoritesShopsList() {
		return favoritesShopsList;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public UserFavoritesShops getUserFavoritesShops() {
		return userFavoritesShops;
	}

	public void setUserFavoritesShops(UserFavoritesShops userFavoritesShops) {
		this.userFavoritesShops = userFavoritesShops;
	}

	public UserFavoritesCompanyprofile getUserFavoritesProfile() {
		return userFavoritesProfile;
	}

	public void setUserFavoritesProfile(
			UserFavoritesCompanyprofile userFavoritesProfile) {
		this.userFavoritesProfile = userFavoritesProfile;
	}

	public List<UserFavoritesCompanyprofile> getFavoritesProfileList() {
		return favoritesProfileList;
	}

	public UserFavoritesCategory getUserFavoritesCategory() {
		return userFavoritesCategory;
	}

	public void setUserFavoritesCategory(UserFavoritesCategory userFavoritesCategory) {
		this.userFavoritesCategory = userFavoritesCategory;
	}

	public List<UserFavoritesCategory> getFavoritesCategoriesList() {
		return favoritesCategoriesList;
	}

	public UserFavoritesSearch getUserFavoritesSearch() {
		return userFavoritesSearch;
	}

	public void setUserFavoritesSearch(UserFavoritesSearch userFavoritesSearch) {
		this.userFavoritesSearch = userFavoritesSearch;
	}

	public List<UserFavoritesSearch> getFavoritesSearchList() {
		return favoritesSearchList;
	}

	public void setCount(int count) {
		this.count = count;
	}
}
